package com.insea.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

@Entity
public class Service extends BaseObject{

	private Long id;
	private String numService;
	private String nomService;
	private Set<Etablissement> etablissements = new HashSet<Etablissement>();
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "numService")
	public String getNumService() {
		return this.numService;
	}

	public void setNumService(String numService) {
		this.numService = numService;
	}

	@Column(name = "nomService", length = 1)
	public String getNomService() {
		return this.nomService;
	}

	public void setNomService(String nomService) {
		this.nomService = nomService;
	}
	
	@ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name = "service_etablissement",
            joinColumns = { @JoinColumn(name = "service_id") },
            inverseJoinColumns = @JoinColumn(name = "etablissement_id")
    )
    public Set<Etablissement> getEtablissements() {
        return etablissements;
    }
	
	public void setEtablissements(Set<Etablissement>  etablissements){
		
		this.etablissements=etablissements;
	}

	public boolean equals(Object other) {
		if ((this == other))
			return true;
		if ((other == null))
			return false;
		if (!(other instanceof Service))
			return false;
		Service castOther = (Service) other;

		return ((this.getNumService() == castOther.getNumService()) || (this
				.getNumService() != null && castOther.getNumService() != null && this
				.getNumService().equals(castOther.getNumService())))
				&& ((this.getNomService() == castOther.getNomService()) || (this
						.getNomService() != null
						&& castOther.getNomService() != null && this
						.getNomService().equals(castOther.getNomService())));
	}

	public int hashCode() {
		int result = 17;

		result = 37
				* result
				+ (getNumService() == null ? 0 : this.getNumService()
						.hashCode());
		result = 37
				* result
				+ (getNomService() == null ? 0 : this.getNomService()
						.hashCode());
		return result;
	}

	@Override
	public String toString() {
		return null;
	}

}
